<%-- 
    Document   : product_details
    Created on : Jan 17, 2013, 2:12:11 AM
    Author     : SONY
--%>

<%@page import="model.Product"%>
<%@page import="model.ProductService"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<% if(request.getQueryString() == null) { %>
<p style="font-weight:bold;">Chi tiết sản phẩm không được tìm thấy.</p>
<% } else {
    String pid = request.getQueryString().toString();
    if(pid.equals("details")) {
        pid = request.getAttribute("pid").toString();
    }
    ProductService product_service = new ProductService();
    Product product = product_service.getProductDetails_byPID(pid);
    String pname = product.getProductName();
    String imgname = product.getImageName();
    double price = product.getUnitPrice();
    int qoh = product.getQOH();
    String qoh_str = "Hết Hàng";
    if(qoh > 0) {
        qoh_str = "Còn Hàng";
    }
%>
<form method="post" action="<c:url value="/nonmember/addtocart.do?details" />">
<table border=0>
<tr>
    <td width=160px><img src="../images/products/<%=imgname%>" width='150' height='150' title='<%=pname%>'/></td>
    <td align=center valign=middle>
        <table style="margin-top: 60px;">
            <tr><td style='font-weight: bold;'>Mã sản phẩm</td><td style='padding-left: 20px;'><%=pid%></td></tr>
            <tr><td style='font-weight: bold;'>Tên sản phẩm</td><td style='padding-left: 20px;'><%=pname%></td></tr>
            <tr><td style='font-weight: bold;'>Trạng thái</td><td style='padding-left: 20px;'><%=qoh_str%></td></tr>
            <tr><td style='font-weight: bold;'>Giá</td><td style='padding-left: 20px;color:#b23b08;'><fmt:formatNumber type="currency" currencySymbol="" maxFractionDigits="0" value="<%=price%>"/> đ</td></tr>
        </table></td></tr>
<tr><td colspan=2>

        <table style="margin-right: 60px;" border=0 align="right">
            <tr><td><input type="hidden" name="ProductID" value="<%=pid%>"/>
            <input type="hidden" name="ProductName" value="<%=pname%>"/>
            <input type="hidden" name="ImageName" value="<%=imgname%>"/>
            <input type="hidden" name="UnitPrice" value="<%=price%>"/></td></tr>
            <tr><td>Số Lượng &nbsp;<input type="text" name="quantity"
                    size=20 value="1" style="text-align: right;width: 50px;margin-bottom: 5px;"/></td></tr>
            <tr><td align=center><input type="submit" class="button" value="Chọn Mua"/></td></tr>
    </table>
    </td></tr>
</table>
</form>
<br/>
<br/>
<p><img src="../images/products/<%=imgname%>"/></p>
<%
if(((HttpServletRequest) request).getAttribute("errorMsg") != null) {
        String errorMsg = ((HttpServletRequest) request).getAttribute("errorMsg").toString();
        if(errorMsg.length() > 0) { 
            out.println("<script type=\"text/javascript\">");
            out.println("alert(\"" + errorMsg + "\")");
            out.println("</script>");
        } 
    }
}
%>   